#include "EditorGUIInit.h"
#include "GUINode.h"
#include "GUIButton.h"
#include "GUIWindow.h"
#include "GUITextbox.h"
#include "GUILabel.h"
#include "GUIMenu.h"
#include "GUIComboBox.h"
#include "SceneGraph.h"
#include "IRenderer.h"
#include "EditorGameState.h"
#include "CameraNode.h"
#include "GUITree.h"
#include "TaskManager.h"

void EditorGUIInit( Pointer<ITask>& timer, Pointer<ITask>& physics )
{
	GUINode* gui;
	Pointer<INode> node = gui = new GUINode();
// A camera
	Pointer<INode> camera;
	Pointer<CameraNode> cameraNode(new CameraNode);
	CopyPointer(cameraNode, camera);
	cameraNode->Fovy() = 45.0f;
	cameraNode->Aspect() = (float)Renderer->getWindowWidth()/(float)Renderer->getWindowHeight();
	cameraNode->Near() = 0.1f;
	cameraNode->Far() = 1000.0f;
	Renderer->getWindow()->RegisterHandler("OnWindowResizeEvent", Pointer<EventHandler>( new CEventHandler<CameraNode>(cameraNode, &CameraNode::OnResize)));

	Pointer<EditorGameState> editorGameState = new EditorGameState(cameraNode);
	editorGameState->setTimer(timer);
	TaskManager::getSingleton().SuspendTask(timer);
	editorGameState->setPhysics(physics);
	TaskManager::getSingleton().SuspendTask(physics);
	Pointer<GUIComboBox> combobox;
	Pointer<GUITextbox> textbox;
#pragma region EditorToolbox
	Pointer<GUIWindow> toolbox = new GUIWindow();
	editorGameState->wndToolbox = toolbox;
	Pointer<IGUIElement> element;
	toolbox->Dimensions(Maths::Point<unsigned int>(100, 250));
	toolbox->Location(Maths::Point<unsigned int>(0, 0));
	toolbox->FontColor(0xFF00FF00);
	toolbox->Title(std::string("Toolbox"));

	GUIButton* button = new GUIButton();
	button->Dimensions(Maths::Point<unsigned int>(80, 20));
	button->Location(Maths::Point<unsigned int>(10, 10));
	button->FontColor(0xFFFF0000);
	button->Text(std::string("Create Entity"));
	button->BackgroundColor(0xFFCCCCCC);
	button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::CreateEntity)));
	toolbox->AddChild( button );

	button = new GUIButton();
	button->Dimensions(Maths::Point<unsigned int>(80, 20));
	button->Location(Maths::Point<unsigned int>(10, 30));
	button->FontColor(0xFFFF0000);
	button->Text(std::string("Load Model"));
	button->BackgroundColor(0xFFCCCCCC);
	button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::ShowLoadModelWindow)));
	toolbox->AddChild( button );
	
	button = new GUIButton();
	button->Dimensions(Maths::Point<unsigned int>(80, 20));
	button->Location(Maths::Point<unsigned int>(10, 50));
	button->FontColor(0xFFFF0000);
	button->Text(std::string("Create Terrain"));
	button->BackgroundColor(0xFFCCCCCC);
	button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::ShowCreateTerrainWindow)));
	toolbox->AddChild( button );
	
	button = new GUIButton();
	button->Dimensions(Maths::Point<unsigned int>(80, 20));
	button->Location(Maths::Point<unsigned int>(10, 70));
	button->FontColor(0xFFFF0000);
	button->Text(std::string("SceneGraph"));
	button->BackgroundColor(0xFFCCCCCC);
	button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::DisplaySceneGraph)));
	toolbox->AddChild( button );

	button = new GUIButton();
	button->Dimensions(Maths::Point<unsigned int>(80, 20));
	button->Location(Maths::Point<unsigned int>(10, 90));
	button->FontColor(0xFFFF0000);
	button->Text(std::string("Create Light"));
	button->BackgroundColor(0xFFCCCCCC);
	button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::CreateLight)));
	toolbox->AddChild( button );
	
	button = new GUIButton();
	button->Dimensions(Maths::Point<unsigned int>(80, 20));
	button->Location(Maths::Point<unsigned int>(10, 110));
	button->FontColor(0xFFFF0000);
	button->Text(std::string("Unload State"));
	button->BackgroundColor(0xFFCCCCCC);
	button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::DisplayUnloadState)));
	toolbox->AddChild( button );
	
	button = new GUIButton();
	button->Dimensions(Maths::Point<unsigned int>(80, 20));
	button->Location(Maths::Point<unsigned int>(10, 130));
	button->FontColor(0xFFFF0000);
	button->Text(std::string("Load State"));
	button->BackgroundColor(0xFFCCCCCC);
	button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::DisplayLoadState)));
	toolbox->AddChild( button );
	
	button = new GUIButton();
	button->Dimensions(Maths::Point<unsigned int>(80, 20));
	button->Location(Maths::Point<unsigned int>(10, 150));
	button->FontColor(0xFFFF0000);
	button->Text(std::string("Show Entities"));
	button->BackgroundColor(0xFFCCCCCC);
	button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::DisplayEntityNames)));
	toolbox->AddChild( button );
	
	button = new GUIButton();
	button->Dimensions(Maths::Point<unsigned int>(80, 20));
	button->Location(Maths::Point<unsigned int>(10, 170));
	button->FontColor(0xFFFF0000);
	button->Text(std::string("Load Texture"));
	button->BackgroundColor(0xFFCCCCCC);
	button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::DisplayLoadTexture)));
	toolbox->AddChild( button );

	button = new GUIButton();
	button->Dimensions(Maths::Point<unsigned int>(80, 20));
	button->Location(Maths::Point<unsigned int>(10, 190));
	button->FontColor(0xFFFF0000);
	button->Text(std::string("Create Waypoint"));
	button->BackgroundColor(0xFFCCCCCC);
	button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::DisplayCreateWaypoint)));
	toolbox->AddChild( button );
	
	button = new GUIButton();
	button->Dimensions(Maths::Point<unsigned int>(80, 20));
	button->Location(Maths::Point<unsigned int>(10, 210));
	button->FontColor(0xFFFF0000);
	button->Text(std::string("Create Pathfinder"));
	button->BackgroundColor(0xFFCCCCCC);
	button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::DisplayCreatePathfinder)));
	toolbox->AddChild( button );
	
	CopyPointer(toolbox, element);
	gui->AddElement(element);
	
	Renderer->getWindow()->RegisterHandler("OnMouseLeftDownEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(toolbox, &GUIWindow::ReceiveEvent) ));
	Renderer->getWindow()->RegisterHandler("OnMouseLeftUpEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(toolbox, &GUIWindow::ReceiveEvent) ));
	Renderer->getWindow()->RegisterHandler("OnKeyPressEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(toolbox, &GUIWindow::ReceiveEvent) ));
#pragma endregion

#pragma region EditorProperties
	{
		Pointer<GUIWindow> properties = new GUIWindow();
		editorGameState->wndProperties = properties;
		properties->Dimensions(Maths::Point<unsigned int>(160, Renderer->getWindowHeight()));
		properties->Location(Maths::Point<unsigned int>(Renderer->getWindowWidth()-160, 0));
		properties->FontColor(0xFF00FF00);
		properties->Title(std::string("Properties"));
		properties->Dock(GUIWindow::RIGHT | GUIWindow::TOPBOTTOM);
		//properties->EnterFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::SetPosition)));

		//Pointer<GUILabel> label = new GUILabel();
		//label->Dimensions(Maths::Point<unsigned int>(50, 20));
		//label->Location(Maths::Point<unsigned int>(2, 10));
		//label->FontColor(0xFFFF0000);
		//label->Text(std::string("Position:"));
		//CopyPointer(label, element);
		//properties->AddChild( element );

#pragma region EntityPropertiesMenu
	// Menu
	Pointer<GUIMenu> menu = new GUIMenu();
	editorGameState->mnuEntityProperties = menu;
	menu->Location(Maths::Point<unsigned int>(0, 0));
	menu->FontColor(0xFFFFFFFF);
	menu->Title(std::string(""));
	menu->Visible(false);

	CopyPointer(menu, element);
	properties->AddChild( element );
#pragma region PositionMenuItem
	// Menu Item 1
	Pointer<GUIMenuItem> item1 = new GUIMenuItem();
	item1->FontColor(0xFF000000);
	item1->Title(std::string("Position"));
	menu->AddMenuItem( item1 );

	textbox = new GUITextbox();
	editorGameState->txtPositionX = textbox;
	textbox->Location(Maths::Point<unsigned int>(2, 2));
	textbox->Dimensions(Maths::Point<unsigned int>(50, 20));
	textbox->FontColor(0xFFFF0000);
	textbox->Text(std::string("X"));
	CopyPointer(textbox, element);
	item1->AddElement( element );
	
	textbox = new GUITextbox();
	editorGameState->txtPositionY = textbox;
	textbox->Location(Maths::Point<unsigned int>(56, 2));
	textbox->Dimensions(Maths::Point<unsigned int>(50, 20));
	textbox->FontColor(0xFFFF0000);
	textbox->Text(std::string("Y"));
	CopyPointer(textbox, element);
	item1->AddElement( element );

	textbox = new GUITextbox();
	editorGameState->txtPositionZ = textbox;
	textbox->Location(Maths::Point<unsigned int>(110, 2));
	textbox->Dimensions(Maths::Point<unsigned int>(50, 20));
	textbox->FontColor(0xFFFF0000);
	textbox->Text(std::string("Z"));
	CopyPointer(textbox, element);
	item1->AddElement( element );

	button = new GUIButton();
	button->Location(Maths::Point<unsigned int>(2, 24));
	button->Dimensions(Maths::Point<unsigned int>(80, 20));
	button->FontColor(0xFFFF0000);
	button->Text(std::string("Ok"));
	button->BackgroundColor(0xFFCCCCCC);
	button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::SetPosition)));
	item1->AddElement( button );
#pragma endregion
#pragma region GraphicMenuItem
	// Menu Item 2
	Pointer<GUIMenuItem> item2 = new GUIMenuItem();
	item2->FontColor(0xFF000000);
	item2->Title(std::string("Graphic"));
	menu->AddMenuItem( item2 );

	combobox = new GUIComboBox();
	editorGameState->cmbModelName = combobox;
	combobox->Location(Maths::Point<unsigned int>(2, 2));
	combobox->Dimensions(Maths::Point<unsigned int>(80, 20));
	combobox->FontColor(0xFFFF0000);
	combobox->DefaultText(std::string("Model Name..."));
	CopyPointer(combobox, element);
	item2->AddElement( element );
	
	button = new GUIButton();
	button->Location(Maths::Point<unsigned int>(2, 24));
	button->Dimensions(Maths::Point<unsigned int>(80, 20));
	button->FontColor(0xFFFF0000);
	button->Text(std::string("Ok"));
	button->BackgroundColor(0xFFCCCCCC);
	button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::SetGraphic)));
	item2->AddElement( button );
#pragma endregion
#pragma region NameMenuItem
	// Menu Item 5
	Pointer<GUIMenuItem> item5 = new GUIMenuItem();
	item5->FontColor(0xFF000000);
	item5->Title(std::string("Name"));
	menu->AddMenuItem( item5 );

	textbox = new GUITextbox();
	editorGameState->txtEntityName = textbox;
	textbox->Location(Maths::Point<unsigned int>(2, 2));
	textbox->Dimensions(Maths::Point<unsigned int>(80, 20));
	textbox->FontColor(0xFFFF0000);
	textbox->DefaultText(std::string("Entity Name..."));
	CopyPointer(textbox, element);
	item5->AddElement( element );
	
	button = new GUIButton();
	button->Location(Maths::Point<unsigned int>(2, 24));
	button->Dimensions(Maths::Point<unsigned int>(80, 20));
	button->FontColor(0xFFFF0000);
	button->Text(std::string("Ok"));
	button->BackgroundColor(0xFFCCCCCC);
	button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::SetEntityName)));
	item5->AddElement( button );
#pragma endregion
#pragma region WaypointMenuItem
	// Menu Item 6
	Pointer<GUIMenuItem> item6 = new GUIMenuItem();
	editorGameState->mitEntityWaypoint = item6;
	item6->Visible(false);
	item6->FontColor(0xFF000000);
	item6->Title(std::string("Waypoint"));
	menu->AddMenuItem( item6 );

	textbox = new GUITextbox();
	editorGameState->txtWaypointRadius = textbox;
	textbox->Location(Maths::Point<unsigned int>(2, 2));
	textbox->Dimensions(Maths::Point<unsigned int>(80, 20));
	textbox->FontColor(0xFFFF0000);
	textbox->DefaultText(std::string("Radius..."));
	CopyPointer(textbox, element);
	item6->AddElement( element );
	
	button = new GUIButton();
	button->Location(Maths::Point<unsigned int>(2, 24));
	button->Dimensions(Maths::Point<unsigned int>(80, 20));
	button->FontColor(0xFFFF0000);
	button->Text(std::string("Ok"));
	button->BackgroundColor(0xFFCCCCCC);
	button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::SetWaypointRadius)));
	item6->AddElement( button );
#pragma endregion
#pragma region PathfinderMenuItem
	// Menu Item 7
	Pointer<GUIMenuItem> item7 = new GUIMenuItem();
	editorGameState->mitEntityPathfinder = item7;
	item7->Visible(false);
	item7->FontColor(0xFF000000);
	item7->Title(std::string("Pathfinder"));
	menu->AddMenuItem( item7 );

	textbox = new GUITextbox();
	editorGameState->txtWaypointGroup = textbox;
	textbox->Location(Maths::Point<unsigned int>(2, 2));
	textbox->Dimensions(Maths::Point<unsigned int>(80, 20));
	textbox->FontColor(0xFFFF0000);
	textbox->DefaultText(std::string("Group Name..."));
	CopyPointer(textbox, element);
	item7->AddElement( element );
	
	button = new GUIButton();
	button->Location(Maths::Point<unsigned int>(2, 24));
	button->Dimensions(Maths::Point<unsigned int>(80, 20));
	button->FontColor(0xFFFF0000);
	button->Text(std::string("Ok"));
	button->BackgroundColor(0xFFCCCCCC);
//	button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::SetPathfinderWaypointGroup)));
	item7->AddElement( button );
#pragma endregion
#pragma region RigidBodyMenuItem
	// Menu Item 3
	Pointer<GUIMenuItem> item3 = new GUIMenuItem();
	item3->FontColor(0xFF000000);
	item3->Title(std::string("RigidBody"));
	menu->AddMenuItem( item3 );

	combobox = new GUIComboBox();
	editorGameState->cmbRigidBodyTypes = combobox;
	combobox->Location(Maths::Point<unsigned int>(2, 2));
	combobox->Dimensions(Maths::Point<unsigned int>(100, 20));
	combobox->FontColor(0xFFFF0000);
	combobox->DefaultText(std::string("Rigidbody Shape"));
	combobox->AddItem(std::string("Sphere"));
	combobox->AddItem(std::string("Triangle Mesh"));
	CopyPointer(combobox, element);
	item3->AddElement( element );
	
	textbox = new GUITextbox();
	editorGameState->txtBodyPositionX = textbox;
	textbox->Location(Maths::Point<unsigned int>(2, 24));
	textbox->Dimensions(Maths::Point<unsigned int>(50, 20));
	textbox->FontColor(0xFFFF0000);
	textbox->DefaultText(std::string("Offset X"));
	CopyPointer(textbox, element);
	item3->AddElement( element );
	
	textbox = new GUITextbox();
	editorGameState->txtBodyPositionY = textbox;
	textbox->Location(Maths::Point<unsigned int>(56, 24));
	textbox->Dimensions(Maths::Point<unsigned int>(50, 20));
	textbox->FontColor(0xFFFF0000);
	textbox->Text(std::string("Offset Y"));
	CopyPointer(textbox, element);
	item3->AddElement( element );

	textbox = new GUITextbox();
	editorGameState->txtBodyPositionZ = textbox;
	textbox->Location(Maths::Point<unsigned int>(110, 24));
	textbox->Dimensions(Maths::Point<unsigned int>(50, 20));
	textbox->FontColor(0xFFFF0000);
	textbox->DefaultText(std::string("Offset Z"));
	CopyPointer(textbox, element);
	item3->AddElement( element );

	button = new GUIButton();
	button->Location(Maths::Point<unsigned int>(2, 44));
	button->Dimensions(Maths::Point<unsigned int>(80, 20));
	button->FontColor(0xFFFF0000);
	button->Text(std::string("Ok"));
	button->BackgroundColor(0xFFCCCCCC);
	button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::AddRigidbodyShape)));
	item3->AddElement( button );
	
	button = new GUIButton();
	button->Location(Maths::Point<unsigned int>(84, 44));
	button->Dimensions(Maths::Point<unsigned int>(80, 20));
	button->FontColor(0xFFFF0000);
	button->Text(std::string("Show Shapes"));
	button->BackgroundColor(0xFFCCCCCC);
	button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::ShowRigidBodyShapes)));
	item3->AddElement( button );
#pragma endregion


#pragma endregion


#pragma region LightProperties
		// Menu
		menu = new GUIMenu();
		editorGameState->mnuLightProperties = menu;
		menu->Location(Maths::Point<unsigned int>(0, 0));
		menu->FontColor(0xFFFFFFFF);
		menu->Title(std::string(""));
		menu->Visible(false);

		CopyPointer(menu, element);
		properties->AddChild( element );

	#pragma region PositionMenuItem
		// Menu Item 1
		item1 = new GUIMenuItem();
		item1->FontColor(0xFF000000);
		item1->Title(std::string("Position"));
		menu->AddMenuItem( item1 );

		textbox = new GUITextbox();
		editorGameState->txtLightPositionX = textbox;
		textbox->Location(Maths::Point<unsigned int>(2, 2));
		textbox->Dimensions(Maths::Point<unsigned int>(50, 20));
		textbox->FontColor(0xFFFF0000);
		textbox->DefaultText(std::string("X"));
		CopyPointer(textbox, element);
		item1->AddElement( element );
	
		textbox = new GUITextbox();
		editorGameState->txtLightPositionY = textbox;
		textbox->Location(Maths::Point<unsigned int>(56, 2));
		textbox->Dimensions(Maths::Point<unsigned int>(50, 20));
		textbox->FontColor(0xFFFF0000);
		textbox->DefaultText(std::string("Y"));
		CopyPointer(textbox, element);
		item1->AddElement( element );

		textbox = new GUITextbox();
		editorGameState->txtLightPositionZ = textbox;
		textbox->Location(Maths::Point<unsigned int>(110, 2));
		textbox->Dimensions(Maths::Point<unsigned int>(50, 20));
		textbox->FontColor(0xFFFF0000);
		textbox->DefaultText(std::string("Z"));
		CopyPointer(textbox, element);
		item1->AddElement( element );

		button = new GUIButton();
		button->Location(Maths::Point<unsigned int>(2, 24));
		button->Dimensions(Maths::Point<unsigned int>(80, 20));
		button->FontColor(0xFFFF0000);
		button->Text(std::string("Ok"));
		button->BackgroundColor(0xFFCCCCCC);
		button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::SetLightPosition)));
		item1->AddElement( button );
	#pragma endregion
		CopyPointer(properties, element);
		gui->AddElement(element);

		Renderer->getWindow()->RegisterHandler("OnMouseDownLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(properties, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnMouseUpLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(properties, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnKeyPressEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(properties, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnWindowResizeEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(properties, &GUIWindow::ReceiveEvent) ));
#pragma endregion
	}
#pragma endregion
#pragma region EditorLoadModel	
	{
		Pointer<GUIWindow> loadModel = new GUIWindow();
		editorGameState->wndLoadModel = loadModel;
		loadModel->Visible(false);
		loadModel->Dimensions(Maths::Point<unsigned int>(200, 80));
		loadModel->Location(Maths::Point<unsigned int>((Renderer->getWindowWidth()/2) - 100, (Renderer->getWindowHeight()/2)-40));	// Center
		loadModel->FontColor(0xFF00FF00);
		loadModel->Title(std::string("Load Model"));
		loadModel->EnterFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::LoadModel)));
	
		textbox = new GUITextbox();
		editorGameState->txtModelFileName = textbox;
		textbox->Dimensions(Maths::Point<unsigned int>(196, 20));
		textbox->Location(Maths::Point<unsigned int>(2, 2));
		textbox->FontColor(0xFFFF0000);
		textbox->DefaultText(std::string("Model File Name..."));
		CopyPointer(textbox, element);
		loadModel->AddChild( element );
	
		button = new GUIButton();
		button->Dimensions(Maths::Point<unsigned int>(80, 20));
		button->Location(Maths::Point<unsigned int>(2, 24));
		button->FontColor(0xFFFF0000);
		button->Text(std::string("Load Model"));
		button->BackgroundColor(0xFFCCCCCC);
		button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::LoadModel)));
		loadModel->AddChild( button );
	
		button = new GUIButton();
		button->Dimensions(Maths::Point<unsigned int>(80, 20));
		button->Location(Maths::Point<unsigned int>(86, 24));
		button->FontColor(0xFFFF0000);
		button->Text(std::string("Cancel"));
		button->BackgroundColor(0xFFCCCCCC);
		button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::CancelLoadModel)));
		loadModel->AddChild( button );
	
		CopyPointer(loadModel, element);
		gui->AddElement(element);

		Renderer->getWindow()->RegisterHandler("OnMouseDownLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(loadModel, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnMouseUpLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(loadModel, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnKeyPressEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(loadModel, &GUIWindow::ReceiveEvent) ));
	}
#pragma endregion
#pragma region EditorUnloadState	
	{
		Pointer<GUIWindow> unloadState = new GUIWindow();
		editorGameState->wndUnloadState = unloadState;
		unloadState->Visible(false);
		unloadState->Dimensions(Maths::Point<unsigned int>(200, 80));
		unloadState->Location(Maths::Point<unsigned int>((Renderer->getWindowWidth()/2) - 100, (Renderer->getWindowHeight()/2)-40));	// Center
		unloadState->FontColor(0xFF00FF00);
		unloadState->Title(std::string("Unload State"));
		unloadState->EnterFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::UnloadState)));
	
		textbox = new GUITextbox();
		editorGameState->txtUnloadStateFileName = textbox;
		textbox->Dimensions(Maths::Point<unsigned int>(196, 20));
		textbox->Location(Maths::Point<unsigned int>(2, 2));
		textbox->FontColor(0xFFFF0000);
		textbox->DefaultText(std::string("File Name..."));
		CopyPointer(textbox, element);
		unloadState->AddChild( element );
	
		button = new GUIButton();
		button->Dimensions(Maths::Point<unsigned int>(80, 20));
		button->Location(Maths::Point<unsigned int>(2, 24));
		button->FontColor(0xFFFF0000);
		button->Text(std::string("OK"));
		button->BackgroundColor(0xFFCCCCCC);
		button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::UnloadState)));
		unloadState->AddChild( button );
	
		button = new GUIButton();
		button->Dimensions(Maths::Point<unsigned int>(80, 20));
		button->Location(Maths::Point<unsigned int>(86, 24));
		button->FontColor(0xFFFF0000);
		button->Text(std::string("Cancel"));
		button->BackgroundColor(0xFFCCCCCC);
		button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::CancelUnloadState)));
		unloadState->AddChild( button );
	
		CopyPointer(unloadState, element);
		gui->AddElement(element);

		Renderer->getWindow()->RegisterHandler("OnMouseDownLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(unloadState, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnMouseUpLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(unloadState, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnKeyPressEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(unloadState, &GUIWindow::ReceiveEvent) ));
	}
#pragma endregion
#pragma region EditorLoadTexture
	{
		Pointer<GUIWindow> loadTexture = new GUIWindow();
		editorGameState->wndLoadTexture = loadTexture;
		loadTexture->Visible(false);
		loadTexture->Dimensions(Maths::Point<unsigned int>(200, 80));
		loadTexture->Location(Maths::Point<unsigned int>((Renderer->getWindowWidth()/2) - 100, (Renderer->getWindowHeight()/2)-40));	// Center
		loadTexture->FontColor(0xFF00FF00);
		loadTexture->Title(std::string("Load Texture"));
		loadTexture->EnterFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::LoadTexture)));
	
		textbox = new GUITextbox();
		editorGameState->txtTextureFileName = textbox;
		textbox->Dimensions(Maths::Point<unsigned int>(196, 20));
		textbox->Location(Maths::Point<unsigned int>(2, 2));
		textbox->FontColor(0xFFFF0000);
		textbox->DefaultText(std::string("Image File Name..."));
		CopyPointer(textbox, element);
		loadTexture->AddChild( element );
	
		button = new GUIButton();
		button->Dimensions(Maths::Point<unsigned int>(80, 20));
		button->Location(Maths::Point<unsigned int>(2, 24));
		button->FontColor(0xFFFF0000);
		button->Text(std::string("Load Texture"));
		button->BackgroundColor(0xFFCCCCCC);
		button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::LoadTexture)));
		loadTexture->AddChild( button );
	
		button = new GUIButton();
		button->Dimensions(Maths::Point<unsigned int>(80, 20));
		button->Location(Maths::Point<unsigned int>(86, 24));
		button->FontColor(0xFFFF0000);
		button->Text(std::string("Cancel"));
		button->BackgroundColor(0xFFCCCCCC);
		button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::CancelLoadTexture)));
		loadTexture->AddChild( button );
	
		CopyPointer(loadTexture, element);
		gui->AddElement(element);

		Renderer->getWindow()->RegisterHandler("OnMouseDownLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(loadTexture, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnMouseUpLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(loadTexture, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnKeyPressEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(loadTexture, &GUIWindow::ReceiveEvent) ));
	}
#pragma endregion

#pragma region EditorLoadState	
	{
		Pointer<GUIWindow> loadState = new GUIWindow();
		editorGameState->wndLoadState = loadState;
		loadState->Visible(false);
		loadState->Dimensions(Maths::Point<unsigned int>(200, 80));
		loadState->Location(Maths::Point<unsigned int>((Renderer->getWindowWidth()/2) - 100, (Renderer->getWindowHeight()/2)-40));	// Center
		loadState->FontColor(0xFF00FF00);
		loadState->Title(std::string("Load State"));
		loadState->EnterFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::LoadState)));
	
		textbox = new GUITextbox();
		editorGameState->txtLoadStateFileName = textbox;
		textbox->Dimensions(Maths::Point<unsigned int>(196, 20));
		textbox->Location(Maths::Point<unsigned int>(2, 2));
		textbox->FontColor(0xFFFF0000);
		textbox->DefaultText(std::string("File Name..."));
		CopyPointer(textbox, element);
		loadState->AddChild( element );
	
		button = new GUIButton();
		button->Dimensions(Maths::Point<unsigned int>(80, 20));
		button->Location(Maths::Point<unsigned int>(2, 24));
		button->FontColor(0xFFFF0000);
		button->Text(std::string("OK"));
		button->BackgroundColor(0xFFCCCCCC);
		button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::LoadState)));
		loadState->AddChild( button );
	
		button = new GUIButton();
		button->Dimensions(Maths::Point<unsigned int>(80, 20));
		button->Location(Maths::Point<unsigned int>(86, 24));
		button->FontColor(0xFFFF0000);
		button->Text(std::string("Cancel"));
		button->BackgroundColor(0xFFCCCCCC);
		button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::CancelLoadState)));
		loadState->AddChild( button );
	
		CopyPointer(loadState, element);
		gui->AddElement(element);

		Renderer->getWindow()->RegisterHandler("OnMouseDownLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(loadState, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnMouseUpLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(loadState, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnKeyPressEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(loadState, &GUIWindow::ReceiveEvent) ));
	}
#pragma endregion
#pragma region CreateTerrain
	{
		Pointer<GUIWindow> createTerrain = new GUIWindow();
		editorGameState->wndCreateTerrain = createTerrain;
		createTerrain->Visible(false);
		createTerrain->Dimensions(Maths::Point<unsigned int>(200, 130));
		createTerrain->Location(Maths::Point<unsigned int>((Renderer->getWindowWidth()/2) - 100, (Renderer->getWindowHeight()/2)-40));	// Center
		createTerrain->FontColor(0xFF00FF00);
		createTerrain->Title(std::string("Create Terrain"));
		createTerrain->EnterFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::CreateTerrain)));
	
		textbox = new GUITextbox();
		editorGameState->txtTerrainHeightmapFileName = textbox;
		textbox->Dimensions(Maths::Point<unsigned int>(196, 20));
		textbox->Location(Maths::Point<unsigned int>(2, 2));
		textbox->FontColor(0xFFFF0000);
		textbox->DefaultText(std::string("Heightmap File Name..."));
		CopyPointer(textbox, element);
		createTerrain->AddChild( element );
	
		textbox = new GUITextbox();
		editorGameState->txtTerrainName = textbox;
		textbox->Dimensions(Maths::Point<unsigned int>(196, 20));
		textbox->Location(Maths::Point<unsigned int>(2, 24));
		textbox->FontColor(0xFFFF0000);
		textbox->DefaultText(std::string("Terrain Name..."));
		CopyPointer(textbox, element);
		createTerrain->AddChild( element );
	
		textbox = new GUITextbox();
		editorGameState->txtTerrainPixelStep = textbox;
		textbox->Dimensions(Maths::Point<unsigned int>(80, 20));
		textbox->Location(Maths::Point<unsigned int>(2, 46));
		textbox->FontColor(0xFFFF0000);
		textbox->DefaultText(std::string("Pixel step..."));
		CopyPointer(textbox, element);
		createTerrain->AddChild( element );
	
		textbox = new GUITextbox();
		editorGameState->txtTerrainTextures = textbox;
		textbox->Dimensions(Maths::Point<unsigned int>(196, 20));
		textbox->Location(Maths::Point<unsigned int>(2, 68));
		textbox->FontColor(0xFFFF0000);
		textbox->DefaultText(std::string("Textures... (';' delimiter)"));
		CopyPointer(textbox, element);
		createTerrain->AddChild( element );

		button = new GUIButton();
		button->Dimensions(Maths::Point<unsigned int>(80, 20));
		button->Location(Maths::Point<unsigned int>(2, 90));
		button->FontColor(0xFFFF0000);
		button->Text(std::string("Create Terrain"));
		button->BackgroundColor(0xFFCCCCCC);
		button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::CreateTerrain)));
		createTerrain->AddChild( button );
	
		button = new GUIButton();
		button->Dimensions(Maths::Point<unsigned int>(80, 20));
		button->Location(Maths::Point<unsigned int>(86, 90));
		button->FontColor(0xFFFF0000);
		button->Text(std::string("Cancel"));
		button->BackgroundColor(0xFFCCCCCC);
		button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::CancelCreateTerrain)));
		createTerrain->AddChild( button );
	
		CopyPointer(createTerrain, element);
		gui->AddElement(element);

		Renderer->getWindow()->RegisterHandler("OnMouseDownLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(createTerrain, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnMouseUpLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(createTerrain, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnKeyPressEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(createTerrain, &GUIWindow::ReceiveEvent) ));
	}
#pragma endregion

#pragma region RigidBodyWindow
	{
		Pointer<GUIWindow> rigidbodyDisplay = new GUIWindow();
		editorGameState->wndRigidBodyDisplay = rigidbodyDisplay;
		rigidbodyDisplay->Visible(false);
		rigidbodyDisplay->Dimensions(Maths::Point<unsigned int>(200, 130));
		rigidbodyDisplay->Location(Maths::Point<unsigned int>((Renderer->getWindowWidth()/2) - 100, (Renderer->getWindowHeight()/2)-40));	// Center
		rigidbodyDisplay->FontColor(0xFF00FF00);
		rigidbodyDisplay->Title(std::string("RigidBody Shapes"));
	
		Pointer<GUIButton> ptrbutton = new GUIButton();
		editorGameState->btnRigidBodyDelete = ptrbutton;
		ptrbutton->Location(Maths::Point<unsigned int>(2, 0));
		ptrbutton->Dimensions(Maths::Point<unsigned int>(60, 20));
		ptrbutton->FontColor(0xFFFF0000);
		ptrbutton->Text(std::string("Delete"));
		ptrbutton->BackgroundColor(0xFFCCCCCC);
		ptrbutton->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::DeleteRigidBodyShape)));
	
		CopyPointer(ptrbutton, element);
		rigidbodyDisplay->AddChild( element );
	
		ptrbutton = new GUIButton();
		editorGameState->btnRigidBodyCancel = ptrbutton;
		ptrbutton->Location(Maths::Point<unsigned int>(64, 0));
		ptrbutton->Dimensions(Maths::Point<unsigned int>(60, 20));
		ptrbutton->FontColor(0xFFFF0000);
		ptrbutton->Text(std::string("Cancel"));
		ptrbutton->BackgroundColor(0xFFCCCCCC);
		ptrbutton->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::HideRigidBodyShapes)));
	
		CopyPointer(ptrbutton, element);
		rigidbodyDisplay->AddChild( element );
	
		ptrbutton = new GUIButton();
		editorGameState->btnRigidBodyDeleteAll = ptrbutton;
		ptrbutton->Location(Maths::Point<unsigned int>(126, 0));
		ptrbutton->Dimensions(Maths::Point<unsigned int>(60, 20));
		ptrbutton->FontColor(0xFFFF0000);
		ptrbutton->Text(std::string("Delete All"));
		ptrbutton->BackgroundColor(0xFFCCCCCC);
		ptrbutton->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::DeleteAllRigidBodyShapes)));
	
		CopyPointer(ptrbutton, element);
		rigidbodyDisplay->AddChild( element );
	
		Pointer<GUIListBox> list = new GUIListBox();
		editorGameState->lstRigidBodyShapes = list;
		list->Dimensions(Maths::Point<unsigned int>(200, 130));
		list->Location(Maths::Point<unsigned int>(0,0));
	
		CopyPointer(list, element);
		rigidbodyDisplay->AddChild( element );

		CopyPointer(rigidbodyDisplay, element);
		gui->AddElement(element);
	
		Renderer->getWindow()->RegisterHandler("OnMouseDownLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(rigidbodyDisplay, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnMouseUpLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(rigidbodyDisplay, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnKeyPressEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(rigidbodyDisplay, &GUIWindow::ReceiveEvent) ));
	}
#pragma endregion
#pragma region SceneGraphWindow
	{
		Pointer<GUIWindow> sceneGraphWindow = new GUIWindow();
		editorGameState->wndSceneGraphDisplay = sceneGraphWindow;
		sceneGraphWindow->Dimensions(Maths::Point<unsigned int>(200, 320));
		sceneGraphWindow->Location(Maths::Point<unsigned int>(Renderer->getWindowWidth()/2 - 100, Renderer->getWindowHeight()/2 - 140));
		sceneGraphWindow->FontColor(0xFF00FF00);
		sceneGraphWindow->Visible(false);
		sceneGraphWindow->Title(std::string("Scene Graph"));

		Pointer<GUITree> nodeTree = new GUITree();
		editorGameState->treSceneGraphNodes = nodeTree;
		nodeTree->Location(Maths::Point<unsigned int>(0, 0));
		nodeTree->FontColor(0xFF000000);
		nodeTree->Title(std::string("Root"));
		nodeTree->OnChangeSelected(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::OnSceneNodeChangeSelected)));
		nodeTree->OnDragDropSelected(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::DragDropSceneGraph)));
		CopyPointer(nodeTree, element);
		sceneGraphWindow->AddChild(element);
		
		Pointer<GUIButton> button = new GUIButton();
		button->Dimensions(Maths::Point<unsigned int>(80, 20));
		button->Location(Maths::Point<unsigned int>(2, 278));
		button->FontColor(0xFFFF0000);
		button->Text(std::string("Delete Node"));
		button->BackgroundColor(0xFFCCCCCC);
		button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::DeleteSceneGraphNode)));
		CopyPointer(button, element);
		sceneGraphWindow->AddChild( element );
	
		button = new GUIButton();
		button->Dimensions(Maths::Point<unsigned int>(80, 20));
		button->Location(Maths::Point<unsigned int>(86, 278));
		button->FontColor(0xFFFF0000);
		button->Text(std::string("Close"));
		button->BackgroundColor(0xFFCCCCCC);
		button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::CloseSceneGraph)));
		CopyPointer(button, element);
		sceneGraphWindow->AddChild( element );
	

		CopyPointer(sceneGraphWindow, element);
		gui->AddElement(element);	
	
		Renderer->getWindow()->RegisterHandler("OnMouseMoveEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(sceneGraphWindow, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnMouseLeftDownEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(sceneGraphWindow, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnMouseLeftUpEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(sceneGraphWindow, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnKeyPressEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(sceneGraphWindow, &GUIWindow::ReceiveEvent) ));
	}
#pragma endregion
#pragma region EntityListWindow
	{
		Pointer<GUIWindow> entityListWindow = new GUIWindow();
		editorGameState->wndEntityList = entityListWindow;
		entityListWindow->Visible(false);
		entityListWindow->Dimensions(Maths::Point<unsigned int>(200, 130));
		entityListWindow->Location(Maths::Point<unsigned int>((Renderer->getWindowWidth()/2) - 100, (Renderer->getWindowHeight()/2)-40));	// Center
		entityListWindow->FontColor(0xFF00FF00);
		entityListWindow->Title(std::string("Entites..."));
	
		Pointer<GUIButton> ptrbutton = new GUIButton();
		editorGameState->btnEntityDelete = ptrbutton;
		ptrbutton->Location(Maths::Point<unsigned int>(2, 0));
		ptrbutton->Dimensions(Maths::Point<unsigned int>(60, 20));
		ptrbutton->FontColor(0xFFFF0000);
		ptrbutton->Text(std::string("Delete"));
		ptrbutton->BackgroundColor(0xFFCCCCCC);
		ptrbutton->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::DeleteEntityByName)));
	
		CopyPointer(ptrbutton, element);
		entityListWindow->AddChild( element );
	
		ptrbutton = new GUIButton();
		editorGameState->btnEntityDeleteCancel = ptrbutton;
		ptrbutton->Location(Maths::Point<unsigned int>(64, 0));
		ptrbutton->Dimensions(Maths::Point<unsigned int>(60, 20));
		ptrbutton->FontColor(0xFFFF0000);
		ptrbutton->Text(std::string("Cancel"));
		ptrbutton->BackgroundColor(0xFFCCCCCC);
		ptrbutton->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::HideEntityWindow)));
	
		CopyPointer(ptrbutton, element);
		entityListWindow->AddChild( element );
	
		Pointer<GUIListBox> list = new GUIListBox();
		editorGameState->lstEntityNames = list;
		list->OnSelectedChangedFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::OnEntityListSelectedChange)));
		list->Location(Maths::Point<unsigned int>(0,0));
		list->Dimensions(Maths::Point<unsigned int>(20, 130));
	
		CopyPointer(list, element);
		entityListWindow->AddChild( element );

		CopyPointer(entityListWindow, element);
		gui->AddElement(element);
	
		Renderer->getWindow()->RegisterHandler("OnMouseDownLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(entityListWindow, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnMouseUpLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(entityListWindow, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnKeyPressEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(entityListWindow, &GUIWindow::ReceiveEvent) ));
	}
#pragma endregion

#pragma region CreateWaypoint
	{
		Pointer<GUIWindow> createWaypoint = new GUIWindow();
		editorGameState->wndCreateWaypoint = createWaypoint;
		createWaypoint->Visible(false);
		createWaypoint->Dimensions(Maths::Point<unsigned int>(200, 80));
		createWaypoint->Location(Maths::Point<unsigned int>((Renderer->getWindowWidth()/2) - 100, (Renderer->getWindowHeight()/2)-40));	// Center
		createWaypoint->FontColor(0xFF00FF00);
		createWaypoint->Title(std::string("Create Waypoint"));
		createWaypoint->EnterFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::CreateWaypointComponent)));
	
		textbox = new GUITextbox();
		editorGameState->txtWaypointGroupName = textbox;
		textbox->Dimensions(Maths::Point<unsigned int>(196, 20));
		textbox->Location(Maths::Point<unsigned int>(2, 2));
		textbox->FontColor(0xFFFF0000);
		textbox->DefaultText(std::string("Group Name..."));
		CopyPointer(textbox, element);
		createWaypoint->AddChild( element );
	
		button = new GUIButton();
		button->Dimensions(Maths::Point<unsigned int>(80, 20));
		button->Location(Maths::Point<unsigned int>(2, 24));
		button->FontColor(0xFFFF0000);
		button->Text(std::string("OK"));
		button->BackgroundColor(0xFFCCCCCC);
		button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::CreateWaypointComponent)));
		createWaypoint->AddChild( button );
	
		button = new GUIButton();
		button->Dimensions(Maths::Point<unsigned int>(80, 20));
		button->Location(Maths::Point<unsigned int>(86, 24));
		button->FontColor(0xFFFF0000);
		button->Text(std::string("Cancel"));
		button->BackgroundColor(0xFFCCCCCC);
		button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::CancelCreateWaypoint)));
		createWaypoint->AddChild( button );
	
		CopyPointer(createWaypoint, element);
		gui->AddElement(element);

		Renderer->getWindow()->RegisterHandler("OnMouseDownLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(createWaypoint, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnMouseUpLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(createWaypoint, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnKeyPressEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(createWaypoint, &GUIWindow::ReceiveEvent) ));
	}
#pragma endregion
#pragma region CreatePathfinder
	{
		Pointer<GUIWindow> createPathfinder = new GUIWindow();
		editorGameState->wndCreatePathfinder = createPathfinder;
		createPathfinder->Visible(false);
		createPathfinder->Dimensions(Maths::Point<unsigned int>(200, 80));
		createPathfinder->Location(Maths::Point<unsigned int>((Renderer->getWindowWidth()/2) - 100, (Renderer->getWindowHeight()/2)-40));	// Center
		createPathfinder->FontColor(0xFF00FF00);
		createPathfinder->Title(std::string("Create Pathfinder"));
		createPathfinder->EnterFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::CreatePathfinderComponent)));
	
		textbox = new GUITextbox();
		editorGameState->txtWaypointGroupName = textbox;
		textbox->Dimensions(Maths::Point<unsigned int>(196, 20));
		textbox->Location(Maths::Point<unsigned int>(2, 2));
		textbox->FontColor(0xFFFF0000);
		textbox->DefaultText(std::string("Group Name..."));
		CopyPointer(textbox, element);
		createPathfinder->AddChild( element );
	
		button = new GUIButton();
		button->Dimensions(Maths::Point<unsigned int>(80, 20));
		button->Location(Maths::Point<unsigned int>(2, 24));
		button->FontColor(0xFFFF0000);
		button->Text(std::string("OK"));
		button->BackgroundColor(0xFFCCCCCC);
		button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::CreatePathfinderComponent)));
		createPathfinder->AddChild( button );
	
		button = new GUIButton();
		button->Dimensions(Maths::Point<unsigned int>(80, 20));
		button->Location(Maths::Point<unsigned int>(86, 24));
		button->FontColor(0xFFFF0000);
		button->Text(std::string("Cancel"));
		button->BackgroundColor(0xFFCCCCCC);
		button->ClickFunction(Pointer<Functor>(new CFunctor<EditorGameState>(editorGameState, &EditorGameState::CancelCreatePathfinder)));
		createPathfinder->AddChild( button );
	
		CopyPointer(createPathfinder, element);
		gui->AddElement(element);

		Renderer->getWindow()->RegisterHandler("OnMouseDownLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(createPathfinder, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnMouseUpLeftEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(createPathfinder, &GUIWindow::ReceiveEvent) ));
		Renderer->getWindow()->RegisterHandler("OnKeyPressEvent", Pointer<EventHandler>( new CEventHandler<GUIWindow>(createPathfinder, &GUIWindow::ReceiveEvent) ));
	}
#pragma endregion
#pragma region GameStateEventHandlers
	Renderer->getWindow()->RegisterHandler("OnMouseDownLeftEvent", Pointer<EventHandler>( new CEventHandler<EditorGameState>(editorGameState, &EditorGameState::ReceiveEvent) ));
	Renderer->getWindow()->RegisterHandler("OnMouseMoveEvent", Pointer<EventHandler>( new CEventHandler<EditorGameState>(editorGameState, &EditorGameState::ReceiveEvent) ));
	Renderer->getWindow()->RegisterHandler("OnKeyPressEvent", Pointer<EventHandler>( new CEventHandler<EditorGameState>(editorGameState, &EditorGameState::ReceiveEvent) ));
	Renderer->getWindow()->RegisterHandler("OnKeyReleaseEvent", Pointer<EventHandler>( new CEventHandler<EditorGameState>(editorGameState, &EditorGameState::ReceiveEvent) ));
#pragma endregion

	SceneGraph::getSingleton().Push_Back(Pointer<INode>(node));
	SceneGraph::getSingleton().Push_Back(Pointer<INode>(camera));
}